<?php
    $conn = new mysqli('localhost', 'root', 'root', 'sanxing');

    if ($conn -> connect_error) {
        die('登录失败');
    }

    // 接收前端的参数
    $num =$_GET['num'];
    $limit =$_GET['limit'];
    //这个参数是为了配合模糊查询来添加的
    $txt =$_GET['txt'];

    // 3
    $start = ($num - 1) * $limit;

    $sql = "SELECT * FROM `list` WHERE `name` LIKE '%$txt%' LIMIT $start, $limit";

    $res = $conn -> query($sql);

    $arr = array();

    while ($row = mysqli_fetch_assoc($res)) {
        array_push($arr, $row);
    }

    echo json_encode(array(
        'state' => true,
        'data' => $arr
    ));
?>